﻿using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace OMR.Lib.Database.Tests
{
    [TestClass]
    public class StorageTests
    {
        public static string dbPath = @"D:\Proje\Dropbox\proje\library\OMR.Database\DB_1\";

        [TestMethod]
        public void CreateTest()
        {
            Storage st = new Storage(dbPath);

            var actual = new TestEntity();

            Assert.IsTrue(st.Create(actual));
        }

        [TestMethod]
        public void ReadTest()
        {
            Storage st = new Storage(dbPath);

            var actual = new TestEntity();

            Assert.IsTrue(st.Create(actual), "Create");

            var expected = (TestEntity)st.Read(actual.Id, typeof(TestEntity));

            Assert.AreEqual(actual.Id, expected.Id);
        }

        [TestMethod]
        public void UpdateTest()
        {
            Storage st = new Storage(dbPath);

            var actual = new TestEntity();

            Assert.IsTrue(st.Create(actual), "Create");

            actual.YearsOld -= 5;

            Assert.IsTrue(st.Update(actual), "Update");

            var expected = (TestEntity)st.Read(actual.Id, typeof(TestEntity));

            Assert.AreEqual(actual.Id, expected.Id);
        }

        [TestMethod]
        public void DeleteTest()
        {
            Storage st = new Storage(dbPath);

            var actual = new TestEntity();

            Assert.IsTrue(st.Create(actual), "Create");

            Assert.IsTrue(st.Delete(actual));
        }

        [TestCleanup]
        public void CleanUp()
        {
            foreach (var f in Directory.GetFiles(dbPath))
            {
                File.Delete(f);
            }
        }
    }

}
